{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>company</th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>46</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A</td>\n",
       "      <td>12</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B</td>\n",
       "      <td>49</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A</td>\n",
       "      <td>10</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A</td>\n",
       "      <td>18</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>C</td>\n",
       "      <td>38</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>A</td>\n",
       "      <td>35</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>C</td>\n",
       "      <td>17</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>A</td>\n",
       "      <td>11</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>A</td>\n",
       "      <td>28</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>A</td>\n",
       "      <td>27</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>A</td>\n",
       "      <td>34</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>A</td>\n",
       "      <td>6</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>C</td>\n",
       "      <td>40</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>A</td>\n",
       "      <td>45</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>C</td>\n",
       "      <td>29</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>A</td>\n",
       "      <td>7</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>A</td>\n",
       "      <td>13</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>A</td>\n",
       "      <td>44</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>C</td>\n",
       "      <td>28</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>B</td>\n",
       "      <td>44</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>C</td>\n",
       "      <td>8</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>C</td>\n",
       "      <td>21</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>C</td>\n",
       "      <td>29</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>A</td>\n",
       "      <td>26</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>B</td>\n",
       "      <td>36</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>B</td>\n",
       "      <td>21</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>B</td>\n",
       "      <td>39</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>B</td>\n",
       "      <td>43</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>C</td>\n",
       "      <td>25</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>B</td>\n",
       "      <td>34</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>C</td>\n",
       "      <td>28</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>B</td>\n",
       "      <td>43</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>B</td>\n",
       "      <td>20</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>C</td>\n",
       "      <td>39</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>C</td>\n",
       "      <td>21</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>B</td>\n",
       "      <td>22</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>C</td>\n",
       "      <td>36</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>A</td>\n",
       "      <td>8</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>A</td>\n",
       "      <td>18</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>A</td>\n",
       "      <td>22</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>C</td>\n",
       "      <td>27</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>C</td>\n",
       "      <td>44</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>B</td>\n",
       "      <td>12</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>A</td>\n",
       "      <td>20</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>A</td>\n",
       "      <td>24</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>C</td>\n",
       "      <td>32</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>A</td>\n",
       "      <td>7</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>B</td>\n",
       "      <td>46</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>B</td>\n",
       "      <td>6</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>A</td>\n",
       "      <td>19</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>A</td>\n",
       "      <td>17</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>C</td>\n",
       "      <td>20</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>A</td>\n",
       "      <td>20</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   company  salary  age\n",
       "0        A      46   42\n",
       "1        A      12   43\n",
       "2        B      49   34\n",
       "3        A      10   29\n",
       "4        A      18   32\n",
       "5        C      38   33\n",
       "6        A      15   48\n",
       "7        A      35   22\n",
       "8        C      17   15\n",
       "9        A      11   34\n",
       "10       A      28   45\n",
       "11       A      27   15\n",
       "12       A      34   37\n",
       "13       A       6   46\n",
       "14       C      40   16\n",
       "15       A      45   40\n",
       "16       C      29   16\n",
       "17       A       7   46\n",
       "18       A      13   19\n",
       "19       A      44   39\n",
       "20       C      28   48\n",
       "21       B      44   37\n",
       "22       C       8   26\n",
       "23       C      21   35\n",
       "24       C      29   37\n",
       "25       A      26   34\n",
       "26       B      36   41\n",
       "27       B      21   34\n",
       "28       B      39   29\n",
       "29       B      43   17\n",
       "..     ...     ...  ...\n",
       "70       C      19   36\n",
       "71       C      25   30\n",
       "72       B      34   15\n",
       "73       C      28   17\n",
       "74       B      43   35\n",
       "75       B      20   26\n",
       "76       C      39   41\n",
       "77       C      21   30\n",
       "78       B      22   30\n",
       "79       C      36   29\n",
       "80       A       8   26\n",
       "81       A      18   49\n",
       "82       A      22   31\n",
       "83       C      27   47\n",
       "84       C      44   29\n",
       "85       B      12   15\n",
       "86       A      20   36\n",
       "87       A      24   41\n",
       "88       C      19   30\n",
       "89       C      32   41\n",
       "90       A       7   18\n",
       "91       B      46   23\n",
       "92       A      15   47\n",
       "93       A      15   18\n",
       "94       C      19   49\n",
       "95       B       6   25\n",
       "96       A      19   24\n",
       "97       A      17   44\n",
       "98       C      20   44\n",
       "99       A      20   46\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "company = [\"A\", \"B\", \"C\"]\n",
    "\n",
    "data = pd.DataFrame({\n",
    "    \"company\":[company[x] for x in np.random.randint(0, len(company), 100)],\n",
    "    \"salary\": np.random.randint(5, 50, 100),\n",
    "    \"age\": np.random.randint(15, 50, 100)\n",
    "})\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.groupby.DataFrameGroupBy object at 0x7f2dbb978940>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "group = data.groupby(\"company\")\n",
    "group"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('A',    company  salary  age\n",
       "  0        A      46   42\n",
       "  1        A      12   43\n",
       "  3        A      10   29\n",
       "  4        A      18   32\n",
       "  6        A      15   48\n",
       "  7        A      35   22\n",
       "  9        A      11   34\n",
       "  10       A      28   45\n",
       "  11       A      27   15\n",
       "  12       A      34   37\n",
       "  13       A       6   46\n",
       "  15       A      45   40\n",
       "  17       A       7   46\n",
       "  18       A      13   19\n",
       "  19       A      44   39\n",
       "  25       A      26   34\n",
       "  30       A      32   31\n",
       "  32       A      10   28\n",
       "  33       A      38   37\n",
       "  35       A      15   44\n",
       "  36       A      22   45\n",
       "  38       A      14   27\n",
       "  43       A      46   39\n",
       "  46       A      27   36\n",
       "  47       A      32   33\n",
       "  49       A      11   27\n",
       "  58       A      38   19\n",
       "  59       A      43   41\n",
       "  63       A      49   21\n",
       "  67       A      16   35\n",
       "  80       A       8   26\n",
       "  81       A      18   49\n",
       "  82       A      22   31\n",
       "  86       A      20   36\n",
       "  87       A      24   41\n",
       "  90       A       7   18\n",
       "  92       A      15   47\n",
       "  93       A      15   18\n",
       "  96       A      19   24\n",
       "  97       A      17   44\n",
       "  99       A      20   46), ('B',    company  salary  age\n",
       "  2        B      49   34\n",
       "  21       B      44   37\n",
       "  26       B      36   41\n",
       "  27       B      21   34\n",
       "  28       B      39   29\n",
       "  29       B      43   17\n",
       "  31       B      16   42\n",
       "  34       B      19   25\n",
       "  37       B      49   15\n",
       "  40       B      45   23\n",
       "  41       B      12   28\n",
       "  42       B      37   23\n",
       "  44       B       7   31\n",
       "  45       B      47   20\n",
       "  50       B      35   47\n",
       "  51       B      12   22\n",
       "  53       B      44   36\n",
       "  54       B      20   29\n",
       "  62       B      24   26\n",
       "  68       B      48   24\n",
       "  69       B      41   24\n",
       "  72       B      34   15\n",
       "  74       B      43   35\n",
       "  75       B      20   26\n",
       "  78       B      22   30\n",
       "  85       B      12   15\n",
       "  91       B      46   23\n",
       "  95       B       6   25), ('C',    company  salary  age\n",
       "  5        C      38   33\n",
       "  8        C      17   15\n",
       "  14       C      40   16\n",
       "  16       C      29   16\n",
       "  20       C      28   48\n",
       "  22       C       8   26\n",
       "  23       C      21   35\n",
       "  24       C      29   37\n",
       "  39       C      12   49\n",
       "  48       C      47   21\n",
       "  52       C       7   35\n",
       "  55       C      32   39\n",
       "  56       C      47   15\n",
       "  57       C      23   20\n",
       "  60       C      18   28\n",
       "  61       C      33   39\n",
       "  64       C      19   40\n",
       "  65       C      26   45\n",
       "  66       C      26   20\n",
       "  70       C      19   36\n",
       "  71       C      25   30\n",
       "  73       C      28   17\n",
       "  76       C      39   41\n",
       "  77       C      21   30\n",
       "  79       C      36   29\n",
       "  83       C      27   47\n",
       "  84       C      44   29\n",
       "  88       C      19   30\n",
       "  89       C      32   41\n",
       "  94       C      19   49\n",
       "  98       C      20   44)]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(group)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>company</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>23.292683</td>\n",
       "      <td>34.487805</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>31.107143</td>\n",
       "      <td>27.714286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>26.741935</td>\n",
       "      <td>32.258065</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            salary        age\n",
       "company                      \n",
       "A        23.292683  34.487805\n",
       "B        31.107143  27.714286\n",
       "C        26.741935  32.258065"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "# 求不同　公司员工　的平均年龄和平均薪水，\n",
    "\n",
    "data.groupby(\"company\").agg('mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>company</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>20.0</td>\n",
       "      <td>34.487805</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>35.5</td>\n",
       "      <td>27.714286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>26.0</td>\n",
       "      <td>32.258065</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         salary        age\n",
       "company                   \n",
       "A          20.0  34.487805\n",
       "B          35.5  27.714286\n",
       "C          26.0  32.258065"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# 计算不同公司员工的平均年龄以及薪水的中位数，可以利用字典进行聚合操作的指定：\n",
    "\n",
    "data.groupby(\"company\").agg({'salary':'median', 'age':'mean'})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "avg_salary_dict = data.groupby('company')['salary'].mean().to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'A': 23.29268292682927, 'B': 31.107142857142858, 'C': 26.741935483870968}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "avg_salary_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['avg_salary'] = data['company'].map(avg_salary_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>company</th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "      <th>avg_salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>46</td>\n",
       "      <td>42</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A</td>\n",
       "      <td>12</td>\n",
       "      <td>43</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B</td>\n",
       "      <td>49</td>\n",
       "      <td>34</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A</td>\n",
       "      <td>10</td>\n",
       "      <td>29</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A</td>\n",
       "      <td>18</td>\n",
       "      <td>32</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>C</td>\n",
       "      <td>38</td>\n",
       "      <td>33</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>48</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>A</td>\n",
       "      <td>35</td>\n",
       "      <td>22</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>C</td>\n",
       "      <td>17</td>\n",
       "      <td>15</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>A</td>\n",
       "      <td>11</td>\n",
       "      <td>34</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>A</td>\n",
       "      <td>28</td>\n",
       "      <td>45</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>A</td>\n",
       "      <td>27</td>\n",
       "      <td>15</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>A</td>\n",
       "      <td>34</td>\n",
       "      <td>37</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>A</td>\n",
       "      <td>6</td>\n",
       "      <td>46</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>C</td>\n",
       "      <td>40</td>\n",
       "      <td>16</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>A</td>\n",
       "      <td>45</td>\n",
       "      <td>40</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>C</td>\n",
       "      <td>29</td>\n",
       "      <td>16</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>A</td>\n",
       "      <td>7</td>\n",
       "      <td>46</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>A</td>\n",
       "      <td>13</td>\n",
       "      <td>19</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>A</td>\n",
       "      <td>44</td>\n",
       "      <td>39</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>C</td>\n",
       "      <td>28</td>\n",
       "      <td>48</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>B</td>\n",
       "      <td>44</td>\n",
       "      <td>37</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>C</td>\n",
       "      <td>8</td>\n",
       "      <td>26</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>C</td>\n",
       "      <td>21</td>\n",
       "      <td>35</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>C</td>\n",
       "      <td>29</td>\n",
       "      <td>37</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>A</td>\n",
       "      <td>26</td>\n",
       "      <td>34</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>B</td>\n",
       "      <td>36</td>\n",
       "      <td>41</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>B</td>\n",
       "      <td>21</td>\n",
       "      <td>34</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>B</td>\n",
       "      <td>39</td>\n",
       "      <td>29</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>B</td>\n",
       "      <td>43</td>\n",
       "      <td>17</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>36</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>C</td>\n",
       "      <td>25</td>\n",
       "      <td>30</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>B</td>\n",
       "      <td>34</td>\n",
       "      <td>15</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>C</td>\n",
       "      <td>28</td>\n",
       "      <td>17</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>B</td>\n",
       "      <td>43</td>\n",
       "      <td>35</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>B</td>\n",
       "      <td>20</td>\n",
       "      <td>26</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>C</td>\n",
       "      <td>39</td>\n",
       "      <td>41</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>C</td>\n",
       "      <td>21</td>\n",
       "      <td>30</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>B</td>\n",
       "      <td>22</td>\n",
       "      <td>30</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>C</td>\n",
       "      <td>36</td>\n",
       "      <td>29</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>A</td>\n",
       "      <td>8</td>\n",
       "      <td>26</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>A</td>\n",
       "      <td>18</td>\n",
       "      <td>49</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>A</td>\n",
       "      <td>22</td>\n",
       "      <td>31</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>C</td>\n",
       "      <td>27</td>\n",
       "      <td>47</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>C</td>\n",
       "      <td>44</td>\n",
       "      <td>29</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>B</td>\n",
       "      <td>12</td>\n",
       "      <td>15</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>A</td>\n",
       "      <td>20</td>\n",
       "      <td>36</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>A</td>\n",
       "      <td>24</td>\n",
       "      <td>41</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>30</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>C</td>\n",
       "      <td>32</td>\n",
       "      <td>41</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>A</td>\n",
       "      <td>7</td>\n",
       "      <td>18</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>B</td>\n",
       "      <td>46</td>\n",
       "      <td>23</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>47</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>18</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>49</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>B</td>\n",
       "      <td>6</td>\n",
       "      <td>25</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>A</td>\n",
       "      <td>19</td>\n",
       "      <td>24</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>A</td>\n",
       "      <td>17</td>\n",
       "      <td>44</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>C</td>\n",
       "      <td>20</td>\n",
       "      <td>44</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>A</td>\n",
       "      <td>20</td>\n",
       "      <td>46</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   company  salary  age  avg_salary\n",
       "0        A      46   42   23.292683\n",
       "1        A      12   43   23.292683\n",
       "2        B      49   34   31.107143\n",
       "3        A      10   29   23.292683\n",
       "4        A      18   32   23.292683\n",
       "5        C      38   33   26.741935\n",
       "6        A      15   48   23.292683\n",
       "7        A      35   22   23.292683\n",
       "8        C      17   15   26.741935\n",
       "9        A      11   34   23.292683\n",
       "10       A      28   45   23.292683\n",
       "11       A      27   15   23.292683\n",
       "12       A      34   37   23.292683\n",
       "13       A       6   46   23.292683\n",
       "14       C      40   16   26.741935\n",
       "15       A      45   40   23.292683\n",
       "16       C      29   16   26.741935\n",
       "17       A       7   46   23.292683\n",
       "18       A      13   19   23.292683\n",
       "19       A      44   39   23.292683\n",
       "20       C      28   48   26.741935\n",
       "21       B      44   37   31.107143\n",
       "22       C       8   26   26.741935\n",
       "23       C      21   35   26.741935\n",
       "24       C      29   37   26.741935\n",
       "25       A      26   34   23.292683\n",
       "26       B      36   41   31.107143\n",
       "27       B      21   34   31.107143\n",
       "28       B      39   29   31.107143\n",
       "29       B      43   17   31.107143\n",
       "..     ...     ...  ...         ...\n",
       "70       C      19   36   26.741935\n",
       "71       C      25   30   26.741935\n",
       "72       B      34   15   31.107143\n",
       "73       C      28   17   26.741935\n",
       "74       B      43   35   31.107143\n",
       "75       B      20   26   31.107143\n",
       "76       C      39   41   26.741935\n",
       "77       C      21   30   26.741935\n",
       "78       B      22   30   31.107143\n",
       "79       C      36   29   26.741935\n",
       "80       A       8   26   23.292683\n",
       "81       A      18   49   23.292683\n",
       "82       A      22   31   23.292683\n",
       "83       C      27   47   26.741935\n",
       "84       C      44   29   26.741935\n",
       "85       B      12   15   31.107143\n",
       "86       A      20   36   23.292683\n",
       "87       A      24   41   23.292683\n",
       "88       C      19   30   26.741935\n",
       "89       C      32   41   26.741935\n",
       "90       A       7   18   23.292683\n",
       "91       B      46   23   31.107143\n",
       "92       A      15   47   23.292683\n",
       "93       A      15   18   23.292683\n",
       "94       C      19   49   26.741935\n",
       "95       B       6   25   31.107143\n",
       "96       A      19   24   23.292683\n",
       "97       A      17   44   23.292683\n",
       "98       C      20   44   26.741935\n",
       "99       A      20   46   23.292683\n",
       "\n",
       "[100 rows x 4 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['avg_salary'] = data.groupby('company')['salary'].transform('mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>company</th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "      <th>avg_salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>46</td>\n",
       "      <td>42</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A</td>\n",
       "      <td>12</td>\n",
       "      <td>43</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B</td>\n",
       "      <td>49</td>\n",
       "      <td>34</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A</td>\n",
       "      <td>10</td>\n",
       "      <td>29</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A</td>\n",
       "      <td>18</td>\n",
       "      <td>32</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>C</td>\n",
       "      <td>38</td>\n",
       "      <td>33</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>48</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>A</td>\n",
       "      <td>35</td>\n",
       "      <td>22</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>C</td>\n",
       "      <td>17</td>\n",
       "      <td>15</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>A</td>\n",
       "      <td>11</td>\n",
       "      <td>34</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>A</td>\n",
       "      <td>28</td>\n",
       "      <td>45</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>A</td>\n",
       "      <td>27</td>\n",
       "      <td>15</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>A</td>\n",
       "      <td>34</td>\n",
       "      <td>37</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>A</td>\n",
       "      <td>6</td>\n",
       "      <td>46</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>C</td>\n",
       "      <td>40</td>\n",
       "      <td>16</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>A</td>\n",
       "      <td>45</td>\n",
       "      <td>40</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>C</td>\n",
       "      <td>29</td>\n",
       "      <td>16</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>A</td>\n",
       "      <td>7</td>\n",
       "      <td>46</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>A</td>\n",
       "      <td>13</td>\n",
       "      <td>19</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>A</td>\n",
       "      <td>44</td>\n",
       "      <td>39</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>C</td>\n",
       "      <td>28</td>\n",
       "      <td>48</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>B</td>\n",
       "      <td>44</td>\n",
       "      <td>37</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>C</td>\n",
       "      <td>8</td>\n",
       "      <td>26</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>C</td>\n",
       "      <td>21</td>\n",
       "      <td>35</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>C</td>\n",
       "      <td>29</td>\n",
       "      <td>37</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>A</td>\n",
       "      <td>26</td>\n",
       "      <td>34</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>B</td>\n",
       "      <td>36</td>\n",
       "      <td>41</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>B</td>\n",
       "      <td>21</td>\n",
       "      <td>34</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>B</td>\n",
       "      <td>39</td>\n",
       "      <td>29</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>B</td>\n",
       "      <td>43</td>\n",
       "      <td>17</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>36</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>C</td>\n",
       "      <td>25</td>\n",
       "      <td>30</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>B</td>\n",
       "      <td>34</td>\n",
       "      <td>15</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>C</td>\n",
       "      <td>28</td>\n",
       "      <td>17</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>B</td>\n",
       "      <td>43</td>\n",
       "      <td>35</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>B</td>\n",
       "      <td>20</td>\n",
       "      <td>26</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>C</td>\n",
       "      <td>39</td>\n",
       "      <td>41</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>C</td>\n",
       "      <td>21</td>\n",
       "      <td>30</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>B</td>\n",
       "      <td>22</td>\n",
       "      <td>30</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>C</td>\n",
       "      <td>36</td>\n",
       "      <td>29</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>A</td>\n",
       "      <td>8</td>\n",
       "      <td>26</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>A</td>\n",
       "      <td>18</td>\n",
       "      <td>49</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>A</td>\n",
       "      <td>22</td>\n",
       "      <td>31</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>C</td>\n",
       "      <td>27</td>\n",
       "      <td>47</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>C</td>\n",
       "      <td>44</td>\n",
       "      <td>29</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>B</td>\n",
       "      <td>12</td>\n",
       "      <td>15</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>A</td>\n",
       "      <td>20</td>\n",
       "      <td>36</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>A</td>\n",
       "      <td>24</td>\n",
       "      <td>41</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>30</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>C</td>\n",
       "      <td>32</td>\n",
       "      <td>41</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>A</td>\n",
       "      <td>7</td>\n",
       "      <td>18</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>B</td>\n",
       "      <td>46</td>\n",
       "      <td>23</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>47</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>A</td>\n",
       "      <td>15</td>\n",
       "      <td>18</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>C</td>\n",
       "      <td>19</td>\n",
       "      <td>49</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>B</td>\n",
       "      <td>6</td>\n",
       "      <td>25</td>\n",
       "      <td>31.107143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>A</td>\n",
       "      <td>19</td>\n",
       "      <td>24</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>A</td>\n",
       "      <td>17</td>\n",
       "      <td>44</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>C</td>\n",
       "      <td>20</td>\n",
       "      <td>44</td>\n",
       "      <td>26.741935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>A</td>\n",
       "      <td>20</td>\n",
       "      <td>46</td>\n",
       "      <td>23.292683</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   company  salary  age  avg_salary\n",
       "0        A      46   42   23.292683\n",
       "1        A      12   43   23.292683\n",
       "2        B      49   34   31.107143\n",
       "3        A      10   29   23.292683\n",
       "4        A      18   32   23.292683\n",
       "5        C      38   33   26.741935\n",
       "6        A      15   48   23.292683\n",
       "7        A      35   22   23.292683\n",
       "8        C      17   15   26.741935\n",
       "9        A      11   34   23.292683\n",
       "10       A      28   45   23.292683\n",
       "11       A      27   15   23.292683\n",
       "12       A      34   37   23.292683\n",
       "13       A       6   46   23.292683\n",
       "14       C      40   16   26.741935\n",
       "15       A      45   40   23.292683\n",
       "16       C      29   16   26.741935\n",
       "17       A       7   46   23.292683\n",
       "18       A      13   19   23.292683\n",
       "19       A      44   39   23.292683\n",
       "20       C      28   48   26.741935\n",
       "21       B      44   37   31.107143\n",
       "22       C       8   26   26.741935\n",
       "23       C      21   35   26.741935\n",
       "24       C      29   37   26.741935\n",
       "25       A      26   34   23.292683\n",
       "26       B      36   41   31.107143\n",
       "27       B      21   34   31.107143\n",
       "28       B      39   29   31.107143\n",
       "29       B      43   17   31.107143\n",
       "..     ...     ...  ...         ...\n",
       "70       C      19   36   26.741935\n",
       "71       C      25   30   26.741935\n",
       "72       B      34   15   31.107143\n",
       "73       C      28   17   26.741935\n",
       "74       B      43   35   31.107143\n",
       "75       B      20   26   31.107143\n",
       "76       C      39   41   26.741935\n",
       "77       C      21   30   26.741935\n",
       "78       B      22   30   31.107143\n",
       "79       C      36   29   26.741935\n",
       "80       A       8   26   23.292683\n",
       "81       A      18   49   23.292683\n",
       "82       A      22   31   23.292683\n",
       "83       C      27   47   26.741935\n",
       "84       C      44   29   26.741935\n",
       "85       B      12   15   31.107143\n",
       "86       A      20   36   23.292683\n",
       "87       A      24   41   23.292683\n",
       "88       C      19   30   26.741935\n",
       "89       C      32   41   26.741935\n",
       "90       A       7   18   23.292683\n",
       "91       B      46   23   31.107143\n",
       "92       A      15   47   23.292683\n",
       "93       A      15   18   23.292683\n",
       "94       C      19   49   26.741935\n",
       "95       B       6   25   31.107143\n",
       "96       A      19   24   23.292683\n",
       "97       A      17   44   23.292683\n",
       "98       C      20   44   26.741935\n",
       "99       A      20   46   23.292683\n",
       "\n",
       "[100 rows x 4 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
